package com.id.supaclean.ui.junk

import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.id.supaclean.R
import com.id.supaclean.common.BaseFragment
import com.id.supaclean.utils.GarbageManager

/**
 * Created by YiGo on 2022/6/16.
 */
class CleanFragment : BaseFragment() {

    override fun layoutId(): Int = R.layout.fragment_clean

    val viewModel by activityViewModels<JunkViewModel>()

    override val enabledBack: Boolean
        get() = true

    val adapter by lazy { CleanAdapter(this) }

    override fun initView() {
        super.initView()
        lifecycleScope.launchWhenResumed {
            viewModel.initData()
        }
        adapter.initAdapterData(viewModel.data)
        view?.findViewById<RecyclerView>(R.id.clean_rv)?.layoutManager = LinearLayoutManager(this.requireActivity())
        view?.findViewById<RecyclerView>(R.id.clean_rv)?.adapter = adapter
        view?.findViewById<ImageView>(R.id.clean_fragment_back_iv)?.setOnClickListener {
            this.activity?.finish()
        }
        view?.findViewById<TextView>(R.id.clean_tv)?.setOnClickListener {
            GarbageManager.cleanGarbage(viewModel.preCleanGarbage.toList())
            navigate(R.id.action_cleanFragment_to_junkCleanFragment)
        }
    }

}


